package com.xuyuan.spring.auto.in;

import com.xuyuan.spring.auto.AutoExample3;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 自定义ImportBeanDefinitionRegistrar
 *
 * @author xuyuan
 */
public class CustomImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(AutoExample3.class).getBeanDefinition();
        // registry.registerBeanDefinition(StrUtil.toCamelCase(AutoExample3.class.getSimpleName()), beanDefinition);
    }

    /**
     * importingClassMetadata引入CustomImportBeanDefinitionRegistrar的类信息
     * registry注册bean定义
     * importBeanNameGenerator生成bean名称
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(AutoExample3.class).getBeanDefinition();
        registry.registerBeanDefinition(importBeanNameGenerator.generateBeanName(beanDefinition, registry), beanDefinition);
    }

}
